package controllers.listeners.lexicon;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JOptionPane;

import models.LexiconFileModel;
import models.LexiconModel;

/* Saves the lexicon into a certain directory */
/* actionPerformed when you click the "Save Lexicon File" button */
public class SaveLexiconListener implements ActionListener {
	
	public SaveLexiconListener() {}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		try {
			LexiconModel.write();
			JOptionPane.showMessageDialog(null, "Saved "+ LexiconFileModel.getFile().getName() + " successfully" ,"Save", JOptionPane.PLAIN_MESSAGE);
		}
		catch (IOException ex) {
			JOptionPane.showMessageDialog(null, "Could not save "+ LexiconFileModel.getFile().getName() + ". Please try again." ,"Failed", JOptionPane.ERROR_MESSAGE);
		}
	}
	
}
